package com.dingreading.cloud.admin.controller;

import com.dingreading.cloud.admin.entity.ReaderContest;
import com.dingreading.cloud.admin.service.ReaderContestService;
import com.dingreading.cloud.common.base.R;
import com.dingreading.cloud.common.util.PageBeanDto;
import com.dingreading.cloud.common.util.PageUtil;
import com.mybatisflex.core.paginate.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/system/readerContest")
@Api(tags = "导读教学大赛")
public class ReaderContestController {

    @Resource
    private ReaderContestService readerContestService;


    @ApiOperation(value = "分页列表")
    @PostMapping(value = "/pageList")
    public R<Object> pageList(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "分页公共类") PageUtil pageUtil,
            @ApiParam(value = "员工名/门店名/题目名") @RequestParam(value = "keyword", required = false) String keyword,
            @ApiParam(value = "参赛类型 1.海选 2.决赛") @RequestParam(value = "type", required = false) Integer type,
            @ApiParam(value = "状态 0.待通过 1.通过") @RequestParam(value = "status", required = false) Integer status
    ) {
        Page<ReaderContest> page = readerContestService.pageList(pageUtil, keyword, type, status);

        PageBeanDto data = new PageBeanDto();
        data.setTotal(page.getTotalRow());
        data.setList(page.getRecords());

        return R.ok(data);
    }

    @ApiOperation(value = "获取信息")
    @PostMapping(value = "/getBean", produces = "application/json; charset=UTF-8")
    public R<Object> getBean(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "uid") @RequestParam(value = "uid") String uid
    ) throws Exception {
        ReaderContest data = readerContestService.getByUid(uid);
        return R.ok(data);
    }

    @ApiOperation(value = "更新参赛状态")
    @PostMapping(value = "/updateStatus", produces = "application/json; charset=UTF-8")
    public R<Object> updateStatus(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "uid") @RequestParam(value = "uid") String uid,
            @ApiParam(value = "状态 0.待通过 1.通过") @RequestParam(value = "status") Integer status
    ) throws Exception {
        boolean b = readerContestService.updateStatus(uid, status);
        if (!b)
            return R.fail("操作失败");

        return R.ok();
    }

}
